﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Enterprise.Management.Common;

namespace Enterprise.Management.Caches
{
    public class CookieCache
    {
        public static string GetCookie(string name)
        {
            if (!HttpContext.Current.Request.Cookies.AllKeys.Contains(name)) return string.Empty;
            return HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies[name].Value);
        }

        public static void SetCookie(string name, string value)
        {
            HttpContext.Current.Response.Cookies.Add(new HttpCookie(name, HttpUtility.UrlEncode(value)));
        }

        public static void DeleteCookie(string name)
        {
            HttpContext.Current.Response.SetCookie(new HttpCookie(name) { 
                Expires = DateTime.Now.AddDays(-1)
            });
        }
    }
}